package com.itheima.homework16;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Set;

public class Demo6 {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", "heima001");
        map.put("name", "张三");
        map.put("age", 23);
        map.put("birthday", "1999-09-09");
        /*
        请利用反射的知识，将集合中的
        属性值通过学生实体类的set方法，封装到一个学生对象中，并打印该对象展示。
         */

        Class<Student1> clazz = Student1.class;
        Student1 stu = clazz.getConstructor().newInstance();
        Method[] methods = clazz.getMethods();
        Set<String> keys = map.keySet();
        for (String key : keys) {
            Object o = map.get(key);
            for (Method method : methods) {
                if(method.getName().equalsIgnoreCase("set"+key)){
                    method.invoke(stu,o);

                }
            }
        }

        System.out.println(stu);

    }
}
